package com.example.demo.Task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class TestTask {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    //定义没过3秒执行任务
    @Scheduled(fixedRate = 3000)
    //@Scheduled(cron = "")//cron设置参考http://cron.qqe2.com
    public void reportCurrentTime(){
        System.out.println("定时任务每3秒执行一次："+dateFormat.format(new Date()));
    }
}
